package com.lucy.common.module.rlog;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.Hibernate;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * @author kindear
 * 接口请求日志实体类
 */
@Getter
@Setter
@ToString
@Entity
@Table(name = "api_log")
@ApiModel(value = "接口请求日志",description = "API日志管理")
@EntityListeners(AuditingEntityListener.class)
public class ApiLog implements Serializable {
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    @ApiModelProperty(value = "日志ID",name = "id")
    Long id;

    @ApiModelProperty("功能模块")
    @Column(name = "module")
    String module;

    @ApiModelProperty("操作方法")
    @Column(name = "method")
    String method;

    @ApiModelProperty("方法类路径")
    @Column(name = "clazz")
    String clazz;

    @ApiModelProperty("请求参数")
    @Column(name = "params",length = 2048)
    String params;

    @ApiModelProperty("返回数据")
    @Column(name = "return_data",columnDefinition="TEXT")
    String returnData;

    @ApiModelProperty("内容")
    @Column(name = "content")
    String content;

    @ApiModelProperty("请求状态")
    @Column(name = "status")
    Integer status;


    @ApiModelProperty("操作用户ID")
    @Column(name = "operator_id")
    Long operatorId;

    @ApiModelProperty("操作用户名字")
    @Column(name = "operator")
    String operator;

    @ApiModelProperty("客户端请求IP")
    @Column(name = "client_ip")
    String clientIp;

    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "操作开始时间",name = "startTime")
    @Column(name = "start_time")
    private Date startTime;


    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "操作结束时间",name = "endTime")
    @Column(name = "end_time")
    private Date endTime;


    @ApiModelProperty("耗费时长")
    @Column(name = "total_time")
    private Integer totalTime;

    @CreatedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录创建时间",name = "createdTime")
    @Column(name = "created_time")
    private Date createdTime;

    @LastModifiedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录更新时间",name = "updatedTime")
    @Column(name = "updated_time")
    private Date updatedTime;

}
